package com.delio.server.base.util;

import com.extjs.gxt.ui.client.data.BasePagingLoadConfig;

public class GxtComboBoxPaginate {
	public Integer offset; 
	public Integer limit;	
	public String order = "";
	public Integer tienda_id = null;
	public BasePagingLoadConfig config;
	
	public String searchField; //ingresado por el usuario
    public String searchString;
    
    public String sortField; //ingresado por el usuario
    public String sortDir;  //ingresado por el usuario
    
    public String condition =  "";
		
	
	public void setLimit(Integer limit){
		this.limit = limit;
		this.offset = config.getOffset();
		if(sortField != null){			
			this.order = "order by "+sortField+" "+sortDir;			
		}
		
		if (config.getLimit() > 0) {
	      this.limit = Math.min(offset + config.getLimit(), this.limit);
	    }
		
		this.searchString = config.get("query");
		this.setCondition();	
	}
	
	private void setCondition(){
		String wh = "";       
        
	    wh += " and "+this.searchField+" ";	    
	    wh += " ilike '%"+this.searchString+"%'";
    
	    this.condition += wh;
        
   }
	
}
